package com.example.p001_interview03;

import java.util.concurrent.locks.LockSupport;

/**
 * 两个线程，一个打印ABC...Z，另外一个打印123...26，实现交替顺序打印A1B2C3...Z26
 */
public class CrossPrinter02 {

    static Thread t1 = null, t2 = null;

    public static void main(String[] args) {

        t1 = new Thread(() -> {

            for (int i = 'A'; i <= 'Z'; i++) {
                System.out.print(String.valueOf((char) i));
                LockSupport.unpark(t2);
                LockSupport.park();
            }

        });
        t2 = new Thread(() -> {
            for (int i = 1; i <= 26; i++) {
                LockSupport.park();
                System.out.print(String.valueOf(i));
                LockSupport.unpark(t1);
            }
        });

        t1.start();
        t2.start();
    }

}
